#include <bits/stdc++.h>
using namespace std;
#define yes cout << "YES" << endl
#define no cout << "NO" << endl
using ll = long long;
void solve()
{
    ll n;
    cin >> n;
    vector<double> a(n + 1);
    for (ll i = 1; i <= n; i++)
    {
        cin >> a[i];
    }
    map<ll, ll> mp;
    ll x, y;
    double sum = 0;
    while (cin >> x >> y)
    {
        if (x == 0 && y == 0)
            break;
        mp[x] += y;

    }
    for (ll i=1;i<=n;i++)
    {
        sum += mp[i] * a[i];
        cout << mp[i] << endl;
    }
    printf("%.2lf", sum);
}
int main()
{
    int t = 1;
    // cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}
